import request from '../utils/request'

//前台
//推荐商品列表
export const getRecommendGoodsList = () => {
    return request({
        url: '/goods/recommend',
        method: 'get'
    })
}

//根据商铺id获取商铺的商品列表
export const getShopGoodsList = (params) => {
    return request({
        url: `/goods/list`,
        method: 'get',
        params // 直接传对象
    })
}
//根据分类id查询商品列表
export const getGoodsListByCategoryId = (categoryId) => {
    return request({
        url: `/goods/listByCategoryId`,
        method: 'get',
        params: { categoryId }
    })
}
//根据商品id查询商品详情
export const getGoodsDetail = (id) => {
    return request({
        url: `/goods/detail`,
        method: 'get',
        params: {
            id
        }
    })
}   
//根据商品id查询sku列表
export const getSkuList = (goodsId) => {
    return request({
        url: `/goods/skuList`,
        method: 'get',
        params: {
            goodsId
        }
    })
}
//根据商品id查询参数信息
export const getAttribute = (goodsId) => {
    return request({
        url: `/goods/attr`,
        method: 'get',
        params: {
            id: goodsId
        }
    })
}

//搜索
export const search = ({ data, page = 0, size = 10 }) => {
    return request({
      url: `/goods/search`,
      method: 'get',
      params: { data, page, size }
    })
  }

//后台
//获取商品分类占比
export const getCategoryPercent = () => {
    return request({
        url: '/goods/jiang/categoryPercent',
        method: 'get'
    })
}
//新增商品
export const addGoods = (submitData) => {
    return request({
        url: '/goods/jiang/add',
        method: 'post',
        data: submitData
    })
}
//新增sku
export const addSku = (sku) => {
    return request({
        url: '/goods/jiang/addSku',
        method: 'post',
        data: sku
    })
}
//修改spu内容
export const updateSpu = (spu) => {
    return request({
        url: '/goods/jiang/updateSpu',
        method: 'put',
        data: spu
    })
}

//修改商品上下架状态
export const updateSpuStatus = (id, status) => {
    return request({
        url: '/goods/jiang/updateSpuStatus',
        method: 'put',
        params: { id, status }
    })
}

//修改sku内容
export const updateSku = (sku) => {
    return request({
        url: '/goods/jiang/updateSku',
        method: 'put',
        data: sku
    })
}
//删除商品
export const deleteGoods = (id) => {
    return request({
        url: '/goods/jiang/delete',
        method: 'delete',
        params: { id }
    })
}
//删除sku
export const deleteSku = (id) => {
    return request({
        url: '/goods/jiang/deleteSku',
        method: 'delete',
        params: { id }
    })
}

//后台管理接口
//获取商品列表
export const getAdminGoodsList = (page = 1, pageSize = 10, params = {}) => {
    return request({
        url: '/goods/jiang/list',
        method: 'get',
        params: {
            page,
            pageSize,
            ...params
        }
    })
}


